package com.cj.life.service.web;

import com.cj.life.ex.ServiceException;
import lombok.Data;

/**
 * json响应
 */
@Data
public class JsonResult {

    /**
     * 业务状态码
     */
    private Integer state;
    /**
     * 操作失败时的提示
     */
    private String message;

    public static JsonResult ok(){
        JsonResult jsonResult = new JsonResult();
        jsonResult.state = ServiceCode.OK.getValue();
        return jsonResult;
    }

    public static JsonResult fail(ServiceException e){
        return fail(e.getServiceCode(), e.getMessage());//让我写两份相同代码，妄想！
    }

    public static JsonResult fail(ServiceCode serviceCode, String message){
        JsonResult jsonResult = new JsonResult();
        jsonResult.state = serviceCode.getValue();
        jsonResult.message = message;
        return jsonResult;
    }
}
